
#include "dialogabout.h"
#include "configuration.h"
#include "controls/ftpushbutton.h"
#include "controls/ftpushbuttonicon.h"
#include "controls/ftlabel.h"
#include "controls/ftmessagebox.h"
#include "controls/ftvboxlayout.h"
#include "controls/fthboxlayout.h"
#include "controls/ftbrowser.h"
#include "controls/fttextarea.h"

DialogAbout::DialogAbout() :
    RotatingDialog()
{
    // Version contains the version and program name
    version = new FTLabel( QString("Track@Way %1").arg( VERSION ) );
    version->setFont( FTControls::font( FTControls::FontTitle ) );
    version->setAlignment( Qt::AlignCenter );

    // My name!!!
    author = new FTLabel(tr("Developed by Willy Gardiol"));
    author->setAlignment( Qt::AlignCenter );

    // Support label
    support = new FTTextArea("", 2);
    support->setAlignment( Qt::AlignCenter );
    QString str;
#ifdef CAP_SUPPORTER
    str = tr("Thanks for supporting Track@Way! ");
#else
    support->setText( str + tr("Track YOUR way the WAY you want...") );
#endif

    contact = new FTPushButtonIcon( QIcon( ":/help/contact.png") );
    connect( contact, SIGNAL(clicked()),
             this, SLOT(urlWillygardiol()));

    close = new FTPushButton(tr("Go to Track@Way!"));
    connect( close, SIGNAL(clicked()),
              this, SLOT(accept()) );

    home = new FTPushButtonIcon( QIcon( ":/help/trackaway_48.png"), FTControls::IconBig);
    connect( home, SIGNAL(clicked()),
             this, SLOT(urlHomepage()));

    forums = new FTPushButtonIcon( QIcon( ":/help/forums.png"), FTControls::IconBig);
    connect( forums, SIGNAL(clicked()),
             this, SLOT(urlForums()));

#ifndef CAP_SUPPORTER
    paypal = new FTPushButtonIcon( QIcon( ":/help/paypal.png"), FTControls::IconBig);
    connect( paypal, SIGNAL(clicked()),
             this, SLOT(urlPaypal()));
#endif
}


void DialogAbout::openUrl(QString url)
{
    FTBrowser browser( url );
    browser.exec();
}

void DialogAbout::urlHomepage()
{
    openUrl( "http://www.trackaway.org");
}

void DialogAbout::urlWillygardiol()
{
    FTMessageBox::Info( tr("Contact Willy Gardiol"),
                        tr("To contact Willy Gardiol, please send an email to: <willy@gardiol.org>!"));
}

void DialogAbout::urlPaypal()
{
    openUrl( "http://www.paypal.com");
}

void DialogAbout::urlForums()
{
    openUrl( "http://forums.trackaway.org");
}

QLayout* DialogAbout::createHorizontal()
{
    FTVBoxLayout* grid;
    FTVBoxLayout* vgrid;
    FTHBoxLayout* hgrid;

    grid = new FTVBoxLayout();

    hgrid = new FTHBoxLayout();
    hgrid->addWidget( version );
    hgrid->addWidget( contact );
    hgrid->addWidget( author );
    grid->addLayout( hgrid );

    grid->addWidget( support );

    hgrid = new FTHBoxLayout();
    vgrid = new FTVBoxLayout();
    vgrid->addWidget( home );
#ifndef CAP_SUPPORTER
    vgrid->addWidget( paypal );
#endif
    vgrid->addWidget( forums );
    hgrid->addLayout( vgrid );
    grid->addLayout( hgrid, 2 );

    grid->addWidget( close );
    return grid;
}

QLayout* DialogAbout::createVertical()
{
    FTVBoxLayout* grid = new FTVBoxLayout();
    grid->addWidget( version );
    FTHBoxLayout* authorgrid = new FTHBoxLayout();
    authorgrid->addWidget( author );
    authorgrid->addWidget( contact );
    grid->addLayout( authorgrid );
    grid->addWidget( support );
    FTHBoxLayout* bgrid = new FTHBoxLayout();
    bgrid->addWidget( home );
#ifndef CAP_SUPPORTER
    bgrid->addWidget( paypal );
#endif
    bgrid->addWidget( forums );
    grid->addLayout( bgrid );
    grid->addWidget( close );
    return grid;
}
